package examples.jsf;

import examples.jsf.context.FacesContext;
import examples.jsf.context.impl.FacesContextFactory;
import examples.jsf.lifecycle.Lifecycle;
import examples.jsf.lifecycle.impl.LifecycleImpl;

/**
 * @author Bill
 * @version 2013-05-29
 */
public class FacesServlet {

    private Lifecycle lifecycle = null;
    private FacesContextFactory facesContextFactory = null;

    public void init() {
        lifecycle = new LifecycleImpl();
        facesContextFactory = FactoryFinder.getFactory("");
    }

    public void destroy() {
        lifecycle = null;
        facesContextFactory = null;
    }

    public void service() {
        FacesContext context = facesContextFactory.getFacesContext(lifecycle);

        if (isResourcesRequest(context)) {
            // handle resource processing
        }
        else {
            // Faces request
            lifecycle.execute(context);
            lifecycle.render(context);
        }

        context.release();
    }

    private boolean isResourcesRequest(FacesContext context) {
        return false;  //To change body of created methods use File | Settings | File Templates.
    }

}
